/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;


/**
 * 提供一种将对象转换为Boolean值的转换器，实现了Convertor接口。
 * 这个转换器认为null、1 （作为Long或String）和"OK"是true，其他所有值都是false。
 */
public class BooleanNullSafeReplayConvertor implements Convertor<Boolean> {

    /**
     * 将输入对象转换为Boolean值。
     * @param obj 需要转换的对象。
     * @return 转换后的Boolean值。如果输入为null，则返回false；如果输入为1（Long或String）或"OK"，则返回true；其他情况返回false。
     */
    @Override
    public Boolean convert(Object obj) {
        // 检查对象是否为null
        if (obj == null) {
            return false;
        }
        // 判断对象是否等同于1或"OK"，这里的等同判断支持Long和String类型
        return Long.valueOf(1).equals(obj) || "OK".equals(obj);
    }


}
